"use strict";

const Controller = require('../common/admin')

class GoodsCategoryController extends Controller {

  tableName='goods_category'

  async addGoodsCategory () {
    let {
      category_name, short_name, pid, commission_rate, image, image_adv, is_show, keywords, description
    } = this.ctx.request.body


    let level, parent_id

    if (pid[0] === 0) {
      level = 1
    } else if (pid[0] !== 0 && pid.length === 1) {
      level = 2
    } else {
      level = 3
    }
    
    parent_id = pid = pid[pid.length-1]
    let result = await this.add({category_name, short_name, pid, commission_rate, image, image_adv, is_show, keywords, description, level, parent_id})
 
    this.resData(0, '商品分类添加成功', null)
    
  }


}

module.exports = GoodsCategoryController